<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>圣建资源规划</title>
<script type="text/javascript">
	var data = new Array();
	onload = function() {
		peo.setAttribute("onkeypress", "if (event.keyCode==13){ammo.focus()}");
		ammo.setAttribute("onkeypress", "if (event.keyCode==13){food.focus()}");
		food.setAttribute("onkeypress", "if (event.keyCode==13){par.focus()}");
		par.setAttribute("onkeypress", "if (event.keyCode==13){times.focus()}");
		times.setAttribute("onkeypress", "if (event.keyCode==13){addlist()}");
	}

	addlist = function() {
		var input = document.getElementsByTagName("input")
		var line = {};
		for (var i = 0; i < input.length; i++) {
			if (input[i].type == "text") {
				line[i] = parseInt(input[i].value);
				if (isNaN(line[i])) {
					line[i] = 0;
				}
				input[i].value
			}
		}

		//列表增加:
		var li = document.createElement("span");
		var button = document.createElement("input");
		button.type = "button";
		button.value = data.length;
		li.appendChild(button);
		li.innerHTML += level.selectedOptions[0].innerText + "：" + line[3] + " " + line[4]
				+ " " + line[5] + " " + line[6] + "  次数：" + line[7]+"<br>";
		line[8] = li;
		data[data.length] = line;
		count();
	}
	dellist = function() {
		var obj = event.target || event.srcElement;
		if (obj.type == "button") {
			data[obj.value] = null;
			count();
		}
	}
	count = function() {
		var plus = new Array();
		list.innerHTML = "";
		for (var i = 0; i < data.length; i++) {
			if (data[i] != null) {
				for (var j = 0; j < 7; j++) {
					if (isNaN(plus[j])) {
						plus[j] = 0;
					}
					plus[j] += data[i][j] * data[i][7];
					list.appendChild(data[i][8]);
				}
			}
		}
		if (plus[3] >= 0) {
			sum.innerHTML = "核心：" + plus[0] + " 白票：" + plus[1]
					+ " 蓝票：" + plus[2] + "<br> 人力：" + numformat(plus[3]) + " 弹药："
					+ numformat(plus[4]) + "<br> 口粮：" + numformat(plus[5]) + " 零件："
					+ numformat(plus[6]);
		} else {
			sum.innerHTML = "";
		}

	}
	changelvl=function(){
		var cls = level.value
		switch (parseInt(cls)) {
		case 1:
			white.value = 1;
			core.value = 3;
			blue.value = 0;
			break;
		case 2:
			white.value = 20;
			core.value = 5;
			blue.value = 0;
			break;
		case 3:
			white.value = 50;
			core.value = 10;
			blue.value = 0;
			break;
		case 4:
			blue.value = 1;
			core.value = 2;
			white.value = 0;
			break;
		case 5:
			blue.value = 20;
			core.value = 4;
			white.value = 0;
			break;
		case 6:
			blue.value = 50;
			core.value = 6;
			white.value = 0;
			break;
		case 0:
			blue.value = 0;
			core.value = 0;
			white.value = 0;
		}
	}
	
	changegs = function() {
		//档位
		var cls = level.value
		changelvl()
		
		//公式
		var formula = gs.value
		var lvl = 1;
		if (cls == 1 || cls == 2 || cls == 3) {
			lvl = 10
		} else if (cls==0){
			core.value = 0;
			white.value = 1;
			blue.value = 0;
		}
		switch (formula) {
		case "AR":
			peo.value = 100 * lvl;
			ammo.value = 400 * lvl;
			food.value = 400 * lvl;
			par.value = 200 * lvl;
			break;
		case "RF":
			peo.value = 400 * lvl;
			ammo.value = 100 * lvl;
			food.value = 400 * lvl;
			par.value = 200 * lvl;
			break;
		case "SMG":
			peo.value = 400 * lvl;
			ammo.value = 400 * lvl;
			food.value = 100 * lvl;
			par.value = 200 * lvl;
			break;
		case "MG":
			peo.value = 800 * lvl;
			ammo.value = 800 * lvl;
			food.value = 100 * lvl;
			par.value = 400 * lvl;
			break;
		case "HG":
			peo.value = 130;
			ammo.value = 130;
			food.value = 130;
			par.value = 30;
			level.options[0].selected = true
			changelvl()
			white.value = 1;
			break;
		case "SG":
			if (!(cls == 1 || cls == 2 || cls == 3)) {
				level.options[1].selected = true
				changelvl()
				lvl = 10
			}
			peo.value = 600 * lvl;
			ammo.value = 200 * lvl;
			food.value = 600 * lvl;
			par.value = 400 * lvl;
			break;
		case "低耗妖精":
			if (!(cls == 4 || cls == 5 || cls == 6)) {
				level.options[4].selected = true
				
			}
			changelvl()
			peo.value = 500;
			ammo.value = 500;
			food.value = 500;
			par.value = 500;
			break;
		case "高耗妖精":
			if (!(cls == 4 || cls == 5 || cls == 6)) {
				level.options[4].selected = true
				
			}
			changelvl()
			peo.value = 2000;
			ammo.value = 2000;
			food.value = 2000;
			par.value = 1000;
			break;
		case "空降妖精":
			if (!(level.value == 4 || level.value == 5 || level.value == 6)) {
				level.options[4].selected = true
				changelvl()
			}
			changelvl()
			peo.value = 2000;
			ammo.value = 500;
			food.value = 2000;
			par.value = 1000;
			break;

		}
		
		times.focus()

	}
	
	reset = function() {
		level.options[0].selected = true
		changelvl();
		gs.options[0].selected = true
		changelevel();
		peo.value = 0;
		ammo.value = 0;
		food.value = 0;
		par.value = 0;
	}
	numformat = function(x) {
		if (x >= 10000) {
			return (x / 10000).toFixed(1) + "w";
		}
		return x;
	}
</script>
<style type="text/css">
input {
	width: 40px;
}

</style>
</head>
<body>
	<div id="form">
		<select id="level" onchange="changegs()">
			<option value="0">0档</option>
			<option value="1">1档人形</option>
			<option value="2">2档人形</option>
			<option value="3">3档人形</option>
			<option value="4">1档装备</option>
			<option value="5">2档装备</option>
			<option value="6">3档装备</option>
		</select>
		<input type="text" id="core" placeholder="核心" readonly="readonly">
		<input type="text" id="white" placeholder="白票">
		<input type="text" id="blue" placeholder="蓝票">
		<br> <select id="gs" onchange="changegs()">
			<option>官方公式</option>
			<option>AR</option>
			<option>RF</option>
			<option>SMG</option>
			<option>MG</option>
			<option>HG</option>
			<option>SG</option>
			<option>低耗妖精</option>
			<option>高耗妖精</option>
			<option>空降妖精</option>
		</select>

		<input type="text" id="peo" placeholder="人力" onfocus="this.select();">
		<input type="text" id="ammo" placeholder="弹药" onfocus="this.select();">
		<input type="text" id="food" placeholder="口粮" onfocus="this.select();">
		<input type="text" id="par" placeholder="零件" onfocus="this.select();">
		<input type="text" id="times" placeholder="次数"
			onfocus="if (this.value.length==0){this.value = 1};this.select()">
		<input type="button" id="addlist" value="添加" onclick="addlist()">
		<input type="button" id="reset" value="重置" onclick="reset()">


	</div>
	<div>
		<div id="list" onclick="dellist()">
		</div>
	</div>
	<div id="sum"></div>
</body>
</html>